/*
 * @Date: 2019-08-31 11:54:51
 * @Github: https://github.com/FinnWu
 * @LastEditors: Finnwu
 * @LastEditTime: 2019-08-31 14:10:34
 */


 // 二维数组的查找
function Find(target, array){
    // write code here
    if(!array) {
        return false
    }
    var rows = array.length
    var columns = array[0].length
    var found = false
    if(rows > 0 && columns > 0) {
        var row = 0
        var column = columns - 1
        while(row < rows && column >= 0) {
            console.log(row, column)
            if (array[row][column] === target) {
                found = true
                break
            } else if (array[row][column] > target) {
                column--
            } else {
                row++
            }
        }
    }

    return found
}

var arr = [
    [1,2,8,9],
    [2,4,9,12],
    [4,7,10,13],
    [6,8,11,15]
]

console.log(Find(3, arr))

